package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    /*添加订单*/
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    /*根据用户id查询订单*/
    @Select("select * from orders where user_id = #{userId} and pay_status = 0")
    Orders getByUserId(Long userId);

    /*分页查询订单*/
    List<Orders> pageQueryOrders(Long userId, String status);

    /*根据id查询订单*/
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /*订单搜索*/
    List<Orders> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);

    /*根据订单状态查询订单数量*/
    @Select("select count(1) from orders where status = #{status}")
    Integer getBystatus(Integer toBeConfirmed);

    /*查询订单数据根据状态和时间 */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    /*查询每一天的营业额*/
    Double getTurnover(LocalDateTime beginTime, LocalDateTime endTime, Integer completed);

    Integer getTurnoverInt(LocalDateTime beginTime, LocalDateTime endTime, Integer completed);

    /*指定时间内销量前10*/
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
